//
//  CrazyChatCustomOrderCell.m
//  webSocket
//
//  Created by 马军凯 on 2019/2/21.
//  Copyright © 2019 ZH. All rights reserved.
//

#import "CrazyChatCustomOrderCell.h"

@interface CrazyChatCustomOrderCell ()

@property (nonatomic, strong) UIImageView *customHeadImageView; //头像
@property (nonatomic, strong) UIView *customOrderBackView; //背景
@property (nonatomic, strong) UIImageView *customOrderBackImageView; //背景图片
@property (nonatomic, strong) UIImageView *customOrderImageView; //订单图片
@property (nonatomic, strong) UILabel *customOrderTitleLabel; //订单标题
@property (nonatomic, strong) UILabel *customOrderAttrLabel; //订单属性
@property (nonatomic, strong) UILabel *customOrderPriceLabel; //订单价格
@property (nonatomic, strong) UILabel *customOrderNumLabel; //订单数量
@property (nonatomic, strong) UILabel *customOrderStatusLabel; //订单状态

@end

@implementation CrazyChatCustomOrderCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

+ (instancetype)cellWithTableView:(UITableView *)tableView {
    static NSString *identifier = CrazyChatCustomOrderIdentifier;
    
    //缓存中取
    CrazyChatCustomOrderCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    
    //创建
    if (!cell) {
        cell = [[CrazyChatCustomOrderCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    
    
    return cell;
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor clearColor];
        //头像
        self.customHeadImageView = [[UIImageView alloc] init];
        self.customHeadImageView.frame = CGRectMake(15, 10, 40, 40);
        [self.contentView addSubview:self.customHeadImageView];
        //背景
        self.customOrderBackView = [[UIView alloc] init];
        self.customOrderBackView.frame = CGRectMake(60, 10, CRAZY_SCREEN_WIDTH - 120, 100);
        [self.contentView addSubview:self.customOrderBackView];
        //背景图片
        self.customOrderBackImageView = [[UIImageView alloc] init];
        self.customOrderBackImageView.frame = self.customOrderBackView.bounds;
        self.customOrderBackImageView.image = [[UIImage imageNamed:@"Crazy_chat_leftPic@2x.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(23, 15, 7, 15) resizingMode:UIImageResizingModeStretch];
        [self.customOrderBackView addSubview:self.customOrderBackImageView];
        //图片
        self.customOrderImageView = [[UIImageView alloc] init];
        self.customOrderImageView.frame = CGRectMake(12, 10, 80, 80);
        [self.customOrderBackView addSubview:self.customOrderImageView];
        //标题
        self.customOrderTitleLabel = [[UILabel alloc] init];
        self.customOrderTitleLabel.numberOfLines = 2;
        self.customOrderTitleLabel.font = [UIFont systemFontOfSize:14];
        self.customOrderTitleLabel.textColor = CRAZY_RGBR(33);
        [self.customOrderBackView addSubview:self.customOrderTitleLabel];
        //价格
        self.customOrderPriceLabel = [[UILabel alloc] init];
        self.customOrderPriceLabel.textColor = [UIColor redColor];
        self.customOrderPriceLabel.font = [UIFont systemFontOfSize:14];
        [self.customOrderBackView addSubview:self.customOrderPriceLabel];
        //属性
        self.customOrderAttrLabel = [[UILabel alloc] init];
        self.customOrderAttrLabel.textColor = CRAZY_RGBR(99);
        self.customOrderAttrLabel.font = [UIFont systemFontOfSize:12];
        [self.customOrderBackView addSubview:self.customOrderAttrLabel];
        //数量
        self.customOrderNumLabel = [[UILabel alloc] init];
        self.customOrderNumLabel.textColor = CRAZY_RGBR(99);
        self.customOrderNumLabel.font = [UIFont systemFontOfSize:12];
        [self.customOrderBackView addSubview:self.customOrderNumLabel];
        //查看
        self.customOrderCheckBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        self.customOrderCheckBtn.frame = self.customOrderBackView.bounds;
        [self.customOrderBackView addSubview:self.customOrderCheckBtn];
        //状态
        self.customOrderStatusLabel = [[UILabel alloc] init];
        self.customOrderStatusLabel.frame = CGRectMake(self.customOrderBackView.width - 40 - 12, self.customOrderBackView.height - 10 - 15, 40, 15);
        [self.customOrderStatusLabel corner_radius:15 / 2];
        self.customOrderStatusLabel.backgroundColor = CRAZY_RGB(254, 239, 239);
        self.customOrderStatusLabel.textColor = CRAZY_RGB(244, 126, 127);
        self.customOrderStatusLabel.textAlignment = NSTextAlignmentCenter;
        self.customOrderStatusLabel.font = [UIFont systemFontOfSize:9];
        [self.customOrderBackView addSubview:self.customOrderStatusLabel];
    }
    return self;
}

//赋值
- (void)setCellValueWithHeadURL:(NSString *)headURL picURL:(NSString *)picURL title:(NSString *)title attr:(NSString *)attr price:(NSString *)price count:(NSString *)count status:(NSString *)status {
    //头像
    [self.customHeadImageView sd_setImageWithURL:[NSURL URLWithString:headURL] placeholderImage:CRAZY_DEFAULT_HEADIMAGE];
    //图片
    [self.customOrderImageView sd_setImageWithURL:[NSURL URLWithString:picURL] placeholderImage:CRAZY_DEFAULT_LOADIMAGE];
    //标题
    self.customOrderTitleLabel.text = title;
    CGSize maxSize = CGSizeMake(self.customOrderBackView.width - 105, 40);
    CGSize size = [self.customOrderTitleLabel sizeThatFits:maxSize];
    self.customOrderTitleLabel.frame = CGRectMake(97, 10, self.customOrderBackView.width - 105, size.height);
    //属性
    self.customOrderAttrLabel.text = ([attr isEqualToString:@""]) ? @"无属性" : attr;
    //价格
    self.customOrderPriceLabel.text = [NSString stringWithFormat:@"%@%@", @"¥", price];
    //数量
    self.customOrderNumLabel.text = [NSString stringWithFormat:@"%@%@", @"x", count];
    //状态
    switch ([status integerValue]) {
        case 0: {
            self.customOrderStatusLabel.text = @"待付款";
        }
            break;
        case 1: {
            self.customOrderStatusLabel.text = @"待配送";
        }
            break;
        case 2: {
            self.customOrderStatusLabel.text = @"配送中";
        }
            break;
        case 3: {
            self.customOrderStatusLabel.text = @"已完成";
        }
            break;
        case 4: {
            self.customOrderStatusLabel.text = @"已关闭";
        }
            break;
        case 5: {
            self.customOrderStatusLabel.text = @"退款中";
        }
            break;
        case 6: {
            self.customOrderStatusLabel.text = @"已取消";
        }
            break;
        default:
            break;
    }
    //价格
    [self.customOrderPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(97);
        make.bottom.mas_equalTo(-10);
    }];
    //属性
    [self.customOrderAttrLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(97);
        make.bottom.mas_equalTo(self.customOrderPriceLabel.mas_top).offset(-8);
        make.width.mas_equalTo(self.customOrderBackView.width - 105);
    }];
    //数量
    [self.customOrderNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.customOrderAttrLabel);
        make.bottom.mas_equalTo(self.customOrderPriceLabel.mas_bottom);
    }];
}


















- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
